package fr.inria.phoenix.scenario.bwsnfirefighting.framework.distributed.environmentsensordevice;

import java.util.HashMap;

import fr.inria.diagen.core.ServiceConfiguration;
import fr.inria.diagen.core.exception.DiaGenException;
import fr.inria.diagen.core.exception.InvocationException;
import fr.inria.diagen.core.network.RemoteServiceInfo;
import fr.inria.diagen.core.service.local.Service;

import java.lang.Boolean;
import fr.inria.phoenix.scenario.bwsnfirefighting.framework.datatype.DeviceStatus;
import java.lang.Integer;
import fr.inria.phoenix.scenario.bwsnfirefighting.framework.datatype.Location;

import fr.inria.diagen.core.module.command.ICommandListener;

/**
 * Define a sensor node with temperature and smoke detection
 *
 * @[57,0]
 * device EnvironmentSensorDevice extends LocatedDevice {
 *   attribute dangerousmaterial as Boolean;
 *   attribute id as Integer;
 *   source smoke as Boolean;
 *   source temperature as Integer;
 *   source status as DeviceStatus;
 * }
 */
public abstract class EnvironmentSensorDevice extends Service implements ICommandListener {

  /**
     * @param serviceConfiguration
     */
    public EnvironmentSensorDevice(ServiceConfiguration serviceConfiguration , fr.inria.phoenix.scenario.bwsnfirefighting.framework.datatype.Location location, java.lang.Boolean dangerousmaterial, java.lang.Integer id) {
      super("EnvironmentSensorDevice", serviceConfiguration, GeneratedFramework.getInstance());
      setLocation(location);
      setDangerousmaterial(dangerousmaterial);
      setId(id);
    }

    @Override
    public final HashMap<String, Object> getAttributes() {
        HashMap<String, Object> attributes = new HashMap<String, Object>();
    
        attributes.put("location",location);
        attributes.put("dangerousmaterial",dangerousmaterial);
        attributes.put("id",id);

        return attributes;
    }
    
    private fr.inria.phoenix.scenario.bwsnfirefighting.framework.datatype.Location location;

    /**
     * @[29,11]
     * attribute location as Location;
     * @param newLocationValue
     */
    protected void setLocation(fr.inria.phoenix.scenario.bwsnfirefighting.framework.datatype.Location newLocationValue) {
      if (location != newLocationValue) {
        location = newLocationValue;
        updateAttributes();
      }
    }

    /**
     * @[29,11]
     * attribute location as Location;
     * @return
     */  
    public fr.inria.phoenix.scenario.bwsnfirefighting.framework.datatype.Location getLocation() {
      return location;
    }

    private java.lang.Boolean dangerousmaterial;

    /**
     * @[59,11]
     * attribute dangerousmaterial as Boolean;
     * @param newDangerousmaterialValue
     */
    protected void setDangerousmaterial(java.lang.Boolean newDangerousmaterialValue) {
      if (dangerousmaterial != newDangerousmaterialValue) {
        dangerousmaterial = newDangerousmaterialValue;
        updateAttributes();
      }
    }

    /**
     * @[59,11]
     * attribute dangerousmaterial as Boolean;
     * @return
     */  
    public java.lang.Boolean getDangerousmaterial() {
      return dangerousmaterial;
    }

    private java.lang.Integer id;

    /**
     * @[58,11]
     * attribute id as Integer;
     * @param newIdValue
     */
    protected void setId(java.lang.Integer newIdValue) {
      if (id != newIdValue) {
        id = newIdValue;
        updateAttributes();
      }
    }

    /**
     * @[58,11]
     * attribute id as Integer;
     * @return
     */  
    public java.lang.Integer getId() {
      return id;
    }

	protected final void _postInitialize() {postInitialize();}
	
	/**
	 *
	 */
	protected void postInitialize() {}

  
    public final Object commandReceived(RemoteServiceInfo rsi, String methodName, Object... args) throws DiaGenException {

    if (methodName.equals("getSmoke")) {
      return getSmoke();
    } else 
    if (methodName.equals("getTemperature")) {
      return getTemperature();
    } else 
    if (methodName.equals("getStatus")) {
      return getStatus();
    }
    
      throw new InvocationException("Undefined method name " + methodName);
    }
  

    private java.lang.Boolean smoke;
    /**
     * @[61,1]
     * source smoke as Boolean;
     */  
    protected void setSmoke(java.lang.Boolean newSmokeValue ) {
      smoke = newSmokeValue;
      getServer().publish("smoke", newSmokeValue); 
    }

    /**
     * @[61,1]
     * source smoke as Boolean;
     */
    protected java.lang.Boolean getSmoke() {
      return smoke;    }

    private java.lang.Integer temperature;
    /**
     * @[60,1]
     * source temperature as Integer;
     */  
    protected void setTemperature(java.lang.Integer newTemperatureValue ) {
      temperature = newTemperatureValue;
      getServer().publish("temperature", newTemperatureValue); 
    }

    /**
     * @[60,1]
     * source temperature as Integer;
     */
    protected java.lang.Integer getTemperature() {
      return temperature;    }

    private fr.inria.phoenix.scenario.bwsnfirefighting.framework.datatype.DeviceStatus status;
    /**
     * @[62,1]
     * source status as DeviceStatus;
     */  
    protected void setStatus(fr.inria.phoenix.scenario.bwsnfirefighting.framework.datatype.DeviceStatus newStatusValue ) {
      status = newStatusValue;
      getServer().publish("status", newStatusValue); 
    }

    /**
     * @[62,1]
     * source status as DeviceStatus;
     */
    protected fr.inria.phoenix.scenario.bwsnfirefighting.framework.datatype.DeviceStatus getStatus() {
      return status;    }
 
}